package com.siteseat.crudeq.broker.transport;

import java.io.IOException;
import java.util.Locale;
import java.util.Set;

import com.siteseat.common.security.Permission;
import com.siteseat.common.security.SecurityException;
import com.siteseat.crudeq.kernel.Message;
import com.siteseat.crudeq.kernel.MessageHistory;
import com.siteseat.crudeq.kernel.MessageId;
import com.siteseat.crudeq.kernel.exception.InvalidChunkException;

/**
 *
 */
public interface BrokerSession {

  byte[] encrypt( byte[] input ) throws SecurityException;

  byte[] decrypt( byte[] input ) throws SecurityException;

  Integer getInternalId();

  short getVersion();

  boolean login( String userName, String password, String clientId, short version, Locale locale )
          throws InterruptedException;

  boolean isAuthenticated();
  
  boolean isConnected();

  void ensureGranted( String resourceName, Permission permission ) throws SecurityException;

  MessageHistory fetchMessage( MessageId lastMsgId ) throws InvalidChunkException, QueueNotExistsException;

  Message prepareMessage( Integer queueId, int messageSize ) throws QueueNotExistsException, InterruptedException,
          IOException;

  void commitMessage( Message msg ) throws QueueNotExistsException;

  void rollbackMessage( Message msg ) throws QueueNotExistsException;

  void close();

  void updateAccessTime();

  long getLastAccessTimeByMilliseconds();

  Locale getLocale();
  
  void subscribe( Set<Integer> queueIds ) throws InterruptedException;
  
  void unsubscribe( Set<Integer> queueIds ) throws InterruptedException;
  
  void startWaitMessage();
  
  void stopWaitMessage();

}
